import React, { Component } from 'react';
import { Text, Image, View, TextInput, TouchableOpacity } from 'react-native';
import { unitWidth } from '../constants/AdapterUtil';
import { MyHeader } from '../components/MyHeader';
import Colors from '../constants/Colors';
import { postFetch } from '../constants/HttpExtension';
import { show } from '../constants/Toast';
import { api_member_info_updateUserInfo } from '../constants/HttpServices';
import { SubmitButton1 } from '../components/Button';
import { MyInput1 } from '../components/Input';
import TextUtil from '../constants/TextUtil';

export default class PersonalAuthenticationScreen extends Component {

    constructor(props) {
        super(props)

        const { navigation } = this.props;
        this.state = {
            realname: global.userInfo.realname ? global.userInfo.realname : '',
            idnumber: global.userInfo.idnumber ? global.userInfo.idnumber : ''
        }
    }

    componentWillMount() {

    }

    componentWillUnmount() {

    };

    render() {
        return (
            <View style={{ flex: 1, backgroundColor: Colors.colorEF }}>
                <MyHeader title='实名认证' leftImg={require('../res/ic_arrow_left.png')} leftClick={() => { this.props.navigation.pop() }} />
                <MyInput1
                    style={{ marginTop: 0 * unitWidth }}
                    onChangeText={this.onRealNameTextChange.bind(this)}
                    title={
                        <Text style={{ color: Colors.black, fontSize: 15 }}>姓名：</Text>
                    }
                    maxLength={20}
                    placeholder='请输入姓名'
                    value={this.state.realname} isLast={false} />
                <MyInput1
                    style={{ marginTop: 0 * unitWidth }}
                    onChangeText={this.onIdNumberTextChange.bind(this)}
                    title={
                        <Text style={{ color: Colors.black, fontSize: 15 }}>身份证号：</Text>
                    }
                    maxLength={20}
                    placeholder='请输入身份证号'
                    value={this.state.idnumber} isLast={true} filterType={3} />
                <SubmitButton1 style={{ marginTop: 294 * unitWidth, alignSelf: 'center' }} text='提交认证' onPress={() => {
                    this.submit();
                }} />
            </View>
        );
    }

    onRealNameTextChange(text) {
        this.setState({
            realname: text
        })
    }

    onIdNumberTextChange(text) {
        this.setState({
            idnumber: text,
        })
    }

    submit() {
        let params = {
            'realname': this.state.realname,
            'idnumber': this.state.idnumber,
        }
        postFetch(api_member_info_updateUserInfo, params, {
            success: (response) => {
                show('上传成功');
                this.props.navigation.pop();
            },
            fail: (response) => {
                show(response.result.message);
            }
        })
    }
}